package com.qsmx.qingqiuticket.app.delegate.back.camera.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.qsmx.qingqiuticket.app.R;
import com.qsmx.qingqiuticket.app.delegate.back.adapter.VersionAdapter;
import com.qsmx.qingqiuticket.app.delegate.back.camera.holder.ImgHolder;

import java.util.List;

public class ImgAdapter extends RecyclerView.Adapter<ImgHolder> {

    private Context mContext;

    private List<String> mImgs;

    //定义接口
    public static interface OnItemClickListener {
        void onItemClick(View view, int position);
    }

    //声明自定义的监听接口
    private ImgAdapter.OnItemClickListener monItemClickListener = null;

    //提供set方法
    public void setonItemClickListener(ImgAdapter.OnItemClickListener listener) {
        this.monItemClickListener = listener;
    }

    public ImgAdapter(Context mContext) {
        this.mContext = mContext;
    }

    public void setImgs(List<String> Imgs) {
        this.mImgs = Imgs;
    }

    @NonNull
    @Override
    public ImgHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ImgHolder(LayoutInflater.from(mContext).inflate(R.layout.adapter_img, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull ImgHolder holder, @SuppressLint("RecyclerView") int position) {
        Glide.with(mContext).load(mImgs.get(position)).into(holder.ivImg);

        holder.ivImg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (monItemClickListener != null) {
                    monItemClickListener.onItemClick(view, position);
                }
            }
        });
    }

    @Override
    public int getItemCount() {

        if (mImgs != null && mImgs.size() > 0) {
            return mImgs.size();
        } else {
            return 0;
        }
    }
}
